#-*- coding: utf-8 -*-
__author__ = 'kilo'

import cv2
import numpy as np
from matplotlib import pyplot as plt

def dummy(v):
   print "value "+str(v)

def example_2(img):
    """Webcambild live blur mit Tiefpassfilter, boxFilter()"""
    camera = cv2.VideoCapture(0)

    #create the window where the boxFiltered image will be shown
    cv2.namedWindow("boxFilter")

    #create a trackbar that controlls the ksize.X value
    cv2.createTrackbar("ksize.X","boxFilter",1,200,dummy)

    #create a trackbar that controlls the ksize.Y value
    cv2.createTrackbar("ksize.Y","boxFilter",1,200,dummy)

    #create a trackbar that controlls the ksize.Y value
    #cv2.createTrackbar("ddepth","boxFilter",2,10,dummy)

    while True:
        f,img = camera.read()
        #boxFilter the image with the selected parameters in the trackbars
        img2 = cv2.boxFilter(img,-1,(cv2.getTrackbarPos("ksize.X","boxFilter"),cv2.getTrackbarPos("ksize.Y","boxFilter")))
        cv2.imshow("boxFilter",img2)
        if (cv2.waitKey(5) != -1):
            break

def example_1(img):
    """Ein Bild mit blur() weichzeichnen"""
    img = cv2.imread(img)

    blur = cv2.blur(img,(5,5))

    plt.subplot(121),plt.imshow(img),plt.title('Original')
    plt.xticks([]), plt.yticks([])
    plt.subplot(122),plt.imshow(blur),plt.title('Blurred')
    plt.xticks([]), plt.yticks([])
    plt.show()


if __name__ == "__main__":
    img = 'cover_left.JPG'
    example_1(img)
    example_2(img)